import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { Observable, from } from 'rxjs';
import {tap} from 'rxjs/operators'
@Injectable()
export class LoggingInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    console.log('拦截器');
    const request = context.switchToHttp().getRequest()
    const {url,method} = request
    const now = Date.now()
    return next.handle().pipe(
      tap((data:any)=>{
        console.log('拦截器====',data);
        console.log(
          `${method}-${url}-${Date.now() - now}ms`,
          context.getClass().name
        );
      })
    );
  }
}
